{{ header }}
<div id="content">
	<div class="page-header">
		<div class="container">
			<div class="float-right">{{ language }}</div>
			<h1>{{ heading_title }}</h1>
		</div>
	</div>
	<div class="container">
		<div class="card">
			<div class="card-header"><i class="fab fa-opencart"></i>&nbsp;&nbsp;&nbsp;{{ text_upgrade }}</div>
			<div class="card-body">
				<fieldset>
					<legend>{{ text_server }}</legend>
					<ol>
						<li>{{ text_error }}</li>
						<li>{{ text_clear }}</li>
						<li>{{ text_admin }}</li>
						<li>{{ text_user }}</li>
						<li>{{ text_setting }}</li>
						<li>{{ text_store }}</li>
					</ol>
				</fieldset>
				<fieldset>
					<legend>{{ text_steps }}</legend>
					<div class="form-group">
						<label class="col-sm-2 control-label">{{ entry_progress }}</label>
						<div class="col-sm-10">
							<div class="progress">
								<div id="progress-bar" class="progress-bar" style="width: 0%;"></div>
							</div>
							<div id="progress-text"></div>
						</div>
					</div>
				</fieldset>
				<div class="row mt-3">
					<div class="col text-right"><button type="button" id="button-continue" data-loading="{{ text_loading }}" class="btn btn-primary">{{ button_continue }}</button></div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript"><!--
var step = 1;

$('#button-continue').on('click', function() {
    step = 1;

    next('index.php?route=upgrade/upgrade_1');

    $('#progress-bar').addClass('progress-bar-success').css('width', '0%').removeClass('progress-bar-danger');
    $('#progress-text').html('');
});

function next(url) {
    $.ajax({
        url: url,
        dataType: 'json',
        beforeSend: function() {
            $('#button-continue').button('loading');
        },
        complete: function() {
            $('#button-continue').button('reset');
        },
        success: function(json) {
            if (json['error']) {
                $('#progress-bar').addClass('progress-bar-danger');
                $('#progress-text').html('<div class="text-danger">' + json['error'] + '</div>');
            }

            if (json['success']) {
                $('#progress-text').html('<span class="text-success">' + json['success'] + '</span>');
            }

            $('#progress-bar').css('width', Math.round((step / {{ total }}) * 100) + '%');

            step++;

            if (json['next']) {
                next(json['next']);
            }
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);

            console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
    });
}
//--></script>
{{ footer }}